﻿using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace FEZThinkSpeak
{
    public class Program
    {
        public static void Main()
        {
            DHT11 MyDHT11 = new DHT11((Cpu.Pin)FEZ_Pin.Digital.Di5, (Cpu.Pin)FEZ_Pin.Digital.Di6);
            ThingSpeak thingSpeak = new ThingSpeak();

            while (true)
            {
                if (MyDHT11.ReadSensor())
                {
                    thingSpeak.UpdateThingSpeak("field1=" + MyDHT11.Temperature.ToString() + 
                                                "&field2=" + MyDHT11.Humidity.ToString() +
                                                "&field3=" + MyDHT11.TemperatureDifference.ToString() +
                                                "&field4=" + MyDHT11.HumidityDifference.ToString());

                    Debug.Print("Temperature = " + MyDHT11.Temperature.ToString() + "°C");
                    Debug.Print("Humidity    = " + MyDHT11.Humidity.ToString() + "%");
                    Debug.Print("TemperatureDifference = " + MyDHT11.TemperatureDifference.ToString() + "");
                    Debug.Print("HumidityDifference = " + MyDHT11.HumidityDifference.ToString() + "");

                }
                else Debug.Print("DHT11 Error : " + MyDHT11.LastError);
                Thread.Sleep(600000);
            }
        }

    }
}
